package org.setaria.control.dataGrid
{
	import flash.events.Event;
	
	import mx.collections.ArrayCollection;
	import mx.controls.CheckBox;
	
	public class CheckBoxHeaderRenderer extends CheckBox
	{
		public function CheckBoxHeaderRenderer()
		{
			super();
			addEventListener(Event.CHANGE, onChangeHandler);
		}
		private var _grid:Object;
		private var _column:Object;
		
		override public function set data(value:Object):void
		{
			_grid = this.listData.owner;
			_column = value;
			this.selected = _column.selected;
			this.label = _column.headerText;
		}
		
		private function onChangeHandler(event:Event):void
		{
			_column.selected = this.selected;
			_grid.invalidateList();
			var datalist:ArrayCollection = _grid.dataProvider as ArrayCollection;
			for each(var item:Object in datalist)
			{
				item[_column.dataField] = this.selected;
			}
		}
	}
}